package com.lifeng.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lifeng.common.util.PageResult;
import com.lifeng.entity.User;
import com.lifeng.mapper.UserMapper;
import com.lifeng.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lifeng.vo.UserVO;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lifeng
 * @since 2025-01-13
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
	// 分页查询(不带条件)
	@Override
	public PageResult<User> findByPage(Integer page, Integer pageSize) {
		Page<User> page1 = this.page(new Page<>(page, pageSize));
		return new PageResult<>(page1.getRecords(),page1.getTotal());
	}

	//分页查询（带条件）
	@Override
	public PageResult<User> search(Integer page, Integer pageSize, UserVO vo) {
		//封装查询条件
		QueryWrapper<User> wrapper = new QueryWrapper<>();
		System.out.println("lifeng");
		wrapper.like(StrUtil.isNotBlank(vo.getUname()), "uname", vo.getUname());
		wrapper.like(StrUtil.isNotBlank(vo.getPhone()), "phone", vo.getPhone());
		wrapper.eq(vo.getSex() != null && vo.getSex() != "", "sex", vo.getSex());
		//根据wrapper包装好的条件进行分页查询
		Page<User> page1 = this.page(new Page<>(page, pageSize), wrapper);

		return new PageResult<>(page1.getRecords(),page1.getTotal());
	}

}
